package com.hq.base.enums;

import com.hq.base.consts.Const;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Collectors;

@Getter
public enum NewsTypeEnum {

    TOP(1,"TOP"),
    guonei(2,"guonei"),
    guoji(3,"guoji"),
    yule(4,"yule"),
    tiyu(5,"tiyu"),
    junshi(6,"junshi"),
    keji(7,"keji"),
    caijing(8,"caijing"),
    shishang(9,"shishang"),
    youxi(10,"youxi"),
    qiche(11,"qiche"),
    jiankang(12,"jiankang");

    NewsTypeEnum(int code, String type) {
        this.code = code;
        this.type = type;
    }
    private Integer code;
    private String type;


    public static String getType(int code){
        Optional<NewsTypeEnum> enumOpt = Arrays.stream(NewsTypeEnum.values()).filter(enums -> enums.getCode() == code).findFirst();
        return  enumOpt.isPresent()?enumOpt.get().getType(): Const.NULL;

    }

    public static int getCode(String type){
        Optional<NewsTypeEnum> enumOpt = Arrays.stream(NewsTypeEnum.values()).filter(enums -> enums.getType().equals(type)).findFirst();
        return  enumOpt.isPresent()?enumOpt.get().getCode(): 0;

    }

}
